package com.huawei.appmarket.service.reserve.game.view;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.appmgr.view.fragment.AppManagerFragment;
import com.huawei.secure.android.common.intent.SafeIntent;
import huawei.widget.HwButton;
import java.lang.ref.WeakReference;
import o.cjk;
import o.cjm;
import o.cjo;
import o.BaseRequest;
import o.djl;
import o.Logger;
import o.ContentManager;
import o.efb;
import o.efi;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class AppReservedFragment extends AppManagerFragment<AppListFragmentProtocol> {
    private static boolean ﾞ = true;
    private HwButton ʹ;
    private djl ʻˋ = null;
    private efi ﹳ;
    private a ﾟ;

    class a extends BroadcastReceiver {
        final /* synthetic */ AppReservedFragment ˏ;

        private a(AppReservedFragment appReservedFragment) {
            this.ˏ = appReservedFragment;
        }

        public void onReceive(Context context, Intent intent) {
            if (this.ˏ.ﹳ == null || this.ˏ.י == null || this.ˏ.ॱˋ() == null || this.ˏ.ॱˋ().isFinishing()) {
                String str = "AppReservedFragment";
                StringBuilder append = new StringBuilder().append("AppReservedBroadCastReceiver onReceive error, appReservedManager = ").append(this.ˏ.ﹳ).append(", provider = ").append(this.ˏ.י).append(", getActivity() = ").append(this.ˏ.ॱˋ()).append(", getActivity().isFinishing() = ");
                boolean z = this.ˏ.ॱˋ() != null && this.ˏ.ॱˋ().isFinishing();
                Logger.e(str, append.append(z).toString());
                this.ˏ.ˋʼ();
                return;
            }
            if (e.ॱ.equals(new SafeIntent(intent).getAction())) {
                this.ˏ.ॱˌ();
            }
        }
    }

    class b implements OnClickListener {
        private final AppReservedFragment ˊ;
        final /* synthetic */ AppReservedFragment ॱ;

        public b(AppReservedFragment appReservedFragment, AppReservedFragment appReservedFragment2) {
            this.ॱ = appReservedFragment;
            this.ˊ = appReservedFragment2;
        }

        public void onClick(View view) {
            cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
            appDetailActivityProtocol.ˏ(new Request("newgame.appoint", null));
            cjk.ˎ().ˋ(this.ॱ.ॱˋ(), new cjm("appdetail.activity", appDetailActivityProtocol));
        }
    }

    static class c implements IServerCallBack {
        private WeakReference<Context> ˊ;
        private WeakReference<AppReservedFragment> ˋ;

        public c(Context context, AppReservedFragment appReservedFragment) {
            this.ˊ = new WeakReference(context);
            this.ˋ = new WeakReference(appReservedFragment);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
            efb.ॱ().ˎ(ContentManager.getInstant().getContext(), responseBean, true);
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            AppReservedFragment appReservedFragment = (AppReservedFragment) this.ˋ.get();
            if (appReservedFragment != null) {
                appReservedFragment.ʿˋ();
                appReservedFragment.ॱˌ();
                appReservedFragment.י();
                appReservedFragment.ٴ();
                return;
            }
            Logger.e("AppReservedFragment", "RefreshReservedCallBack, fragment is null");
        }
    }

    public void ˏ(Bundle bundle) {
        ॱˋ(true);
        ᐝॱ(false);
        super.ˏ(bundle);
        ߺ();
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ˊʼ = ॱˉ();
        this.ˏͺ = ((AppListFragmentProtocol) ˆ()).ॱ().ˋॱ();
        this.ˊ = (ViewGroup) super.ˋ(layoutInflater, viewGroup, bundle);
        this.ʹ = (HwButton) this.ˊ.findViewById(j.ʻᶥ);
        this.ʹ.setOnClickListener(new b(this, this));
        this.ॱॱ = (LinearLayout) this.ˊ.findViewById(j.ˊꜟ);
        if (this.ﹳ.ˊ() == 0) {
            this.ॱॱ.setVisibility(0);
            this.ͺˎ.setVisibility(8);
        }
        י();
        return this.ˊ;
    }

    public int ߵ() {
        return h.ᐝॱ;
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
    }

    public void ˌ() {
        super.ˌ();
        ˈˊ();
        ॱـ();
    }

    public void ˌॱ() {
        ॱˑ();
        super.ˌॱ();
    }

    public void ˋʼ() {
        try {
            if (this.ﾟ != null) {
                this.ᐝ.ˋ(this.ﾟ);
            }
        } catch (IllegalArgumentException e) {
            Logger.e("AppReservedFragment", "unregisterDownloadReceiver, exception: " + e.toString());
        }
        super.ˋʼ();
    }

    public void ˋ(ViewGroup viewGroup, LayoutInflater layoutInflater) {
        this.ͺˎ = (PullUpListView) viewGroup.findViewById(j.ˉॱ);
        this.ͺˎ.setNeedFootView(ﹺ());
    }

    private void ॱʾ() {
        if (this.ॱॱ == null || this.ͺˎ == null) {
            Logger.e("AppReservedFragment", "showDataView error, defaultLayout = " + this.ॱॱ + ", listView = " + this.ͺˎ);
            return;
        }
        if (this.ॱॱ.getVisibility() != 8) {
            this.ॱॱ.setVisibility(8);
        }
        if (this.ͺˎ.getVisibility() != 0) {
            this.ͺˎ.setVisibility(0);
        }
        ٴ();
        י();
    }

    public void ˊʻ() {
        if (this.ॱॱ == null || this.ͺˎ == null) {
            Logger.e("AppReservedFragment", "showDefaultView error, defaultLayout = " + this.ॱॱ + ", listView = " + this.ͺˎ);
            return;
        }
        if (this.ॱॱ.getVisibility() != 0) {
            this.ॱॱ.setVisibility(0);
        }
        if (this.ͺˎ.getVisibility() != 8) {
            this.ͺˎ.setVisibility(8);
        }
        י();
    }

    public void י() {
        boolean z = true;
        if (this.ﹳ == null || ॱˋ() == null || ॱˋ().isFinishing()) {
            String str = "AppReservedFragment";
            StringBuilder append = new StringBuilder().append("setTitle failed. appReservedManager = ").append(this.ﹳ).append(", getActivity() = ").append(ॱˋ()).append(", getActivity().isFinishing() = ");
            if (ॱˋ() == null || !ॱˋ().isFinishing()) {
                z = false;
            }
            Logger.e(str, append.append(z).toString());
            return;
        }
        CharSequence ˎ;
        if (this.ﹳ.ˊ() > 0) {
            ˎ = ˎ(n.ˈʼ, new Object[]{Integer.valueOf(r2)});
        } else {
            ˎ = ॱ(n.ˈʽ);
        }
        ॱˋ().setTitle(ˎ);
    }

    private void ߺ() {
        this.ﹳ = efi.ˎ();
        this.י = this.ﹳ.ˏ(ॱˋ());
    }

    private String ॱˉ() {
        if (ॱˋ() == null || this.ﹳ == null) {
            Logger.e("AppReservedFragment", "createTitle, context = " + ॱˋ() + ", appReservedManager = " + this.ﹳ);
            return "";
        }
        int ˊ = this.ﹳ.ˊ();
        String ॱ = ॱ(n.ˈʽ);
        if (ˊ > 0) {
            return ॱ + ˊ;
        }
        return ॱ;
    }

    private void ॱˑ() {
        if (ॱˋ() == null) {
            Logger.e("AppReservedFragment", "registerBroadCast, context == null");
            return;
        }
        this.ﾟ = new a();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(e.ॱ);
        this.ᐝ.ˏ(this.ﾟ, intentFilter);
    }

    private void ॱˌ() {
        if (this.ﹳ.ॱ(this.י)) {
            ॱʾ();
        } else {
            ˊʻ();
        }
    }

    private void ॱـ() {
        efb.ॱ().ˎ(new c(ॱˋ(), this));
    }

    private void ˈˊ() {
        Logger.ˎ("AppReservedFragment", "NeedShowLoading: " + ﾞ);
        if (ﾞ) {
            if (this.ʻˋ == null) {
                this.ʻˋ = new djl(ॱˋ());
                this.ʻˋ.ˋ(ॱ(n.ʼˉ));
                this.ʻˋ.show();
            } else {
                this.ʻˋ.show();
            }
            ﾞ = false;
        }
    }

    private void ʿˋ() {
        try {
            if (this.ʻˋ != null && this.ʻˋ.isShowing()) {
                this.ʻˋ.dismiss();
            }
        } catch (Throwable e) {
            Logger.ˋ("AppReservedFragment", "dismissLoadingDialog exception:", e);
        }
    }

    public void ˋ(Bundle bundle) {
        super.ˋ(bundle);
        ʿˋ();
        this.ʻˋ = null;
    }
}
